//
//  ClockSimpleBgModifier.swift
//  TimMusic
//
//  Created by nkl on 2024/10/25.
//

import Foundation
import SwiftUI

struct ClockSimpleBgModifier: ViewModifier {
    var size: CGSize = CGSize(width: 66, height: 66)
    var bgColor: Color? = Color.white.opacity(0.15)
    var lineHeight: CGFloat = 3
    var radius: CGFloat = 8
    var offset: CGFloat = 0
    
    func body(content: Content) -> some View {
        bgColor?
            .frame(width: size.width, height: size.height)
            .cornerRadius(radius)
            .shadow(color: "#D2D2D2".toColor()!.toColor().opacity(0.2), radius: 1, y: 1)
            .overlay(
                VStack {
                    content
                }
                .padding(.top, offset)
            )
            .overlayMask {
                Color.black
                    .frame(width: size.width, height: lineHeight)
            }
    }
    
    
}


extension View {
    // 镂空
    func overlayMask(_ content: () -> some View) -> some View {
        return self.mask(
                Rectangle().overlay(
                    content().blendMode(.destinationOut))
        )
    }
}
